<template>
  <div class="xtx-checkbox" @click="changeChecked()">
    <i
      class="iconfont "
      :class="modelValue ? 'icon-checked' : 'icon-unchecked'"
    />
    <span v-if="$slots.default"><slot /></span>
  </div>
</template>

<script>
export default {
  name: 'XtxCheckbox',
  props: {
    modelValue: {
      typeof: Boolean,
      defalut: false
    }
  },
  setup (props, { emit }) {
    const changeChecked = () => {
      // console.log(props.modelValue)
      const temp = !props.modelValue
      // console.log(11111111111, temp)
      emit('update:modelValue', temp)
      emit('change', temp)
    }
    return { changeChecked }
  }
}
</script>

<style scoped lang="less">
.xtx-checkbox {
  display: inline-block;
  margin-right: 2px;
  .icon-checked {
    color: @xtxColor;
    ~ span {
      color: @xtxColor;
    }
  }
  i {
    position: relative;
    top: 1px;
  }
  span {
    margin-left: 2px;
  }
}
</style>
